import QtQuick
import QtQuick.Particles

Rectangle {
    width: 600
    height: 400
    color: "black"

    // 粒子系统
    ParticleSystem {
        id: particleSystem
        anchors.fill: parent

        // 默认粒子图像
        ImageParticle {
            groups: ["default"]
            source: "qrc:/images/dot.png"
        }

        // 被吸引后的粒子图像
        ImageParticle {
            groups: ["attracted"]
            source: "qrc:/images/star.png"
        }

        ParticleGroup {
            name: "default"
            duration: 1000
        }

        ParticleGroup {
            name: "attracted"
            duration: 1000
        }

        // 粒子发射器
        Emitter {
            id: emitter
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            width: parent.width
            height: 1
            emitRate: 100
            lifeSpan: 2500
            size: 12

            group: "default"
            velocity: PointDirection { y: -100; yVariation: 20 }  // 向上发射
            acceleration: PointDirection { y: -20 }  // 向上加速
        }

        GroupGoal {
            id: groupGoal
            system: particleSystem
            groups: ["default"]
            goalState: "attracted"

            x: 0
            y: parent.height / 2
            width: parent.width
            height: 20
            jump: true
        }

        // 目标位置可视化
        Rectangle {
            id: target
            x: groupGoal.x
            y: groupGoal.y
            width: groupGoal.width
            height: groupGoal.height
            radius: 8
            border.color: "cyan"
            color: "black"
        }
    }

    // 说明文本
    Text {
        anchors.bottom: parent.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.bottomMargin: 20
        text: "default粒子组从底部发射至groupGoal区域，转换成attracted粒子组"
        color: "#aaa"
        font.pixelSize: 16
    }
}
